package com.aiyige.page.home.adapter;

import android.view.View;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.home.model.FollowItem;
import com.aiyige.utils.GlideUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

public class RecommendFollowAdapterForGrid extends BaseQuickAdapter<FollowItem, RecommendFollowAdapterForGrid.ViewHolder> {


    public RecommendFollowAdapterForGrid() {
        super(R.layout.recommend_follow_item_for_grid, new LinkedList<FollowItem>());
    }

    @Override
    protected void convert(ViewHolder helper, FollowItem item) {
        helper.bindData(item);
    }


    public class ViewHolder extends BaseViewHolder {
        @BindView(R.id.avatarIv)
        CircleImageView avatarIv;
        @BindView(R.id.userNameTv)
        TextView userNameTv;
        @BindView(R.id.followedLayout)
        View followedLayout;
        @BindView(R.id.followLayout)
        View followLayout;
        FollowItem followItem;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            addOnClickListener(R.id.avatarIv);
        }

        public void bindData(FollowItem followItem) {
            this.followItem = followItem;
            GlideUtil.with(itemView.getContext())
                    .loadAvatar(followItem.getAvatar())
                    .into(avatarIv);
            userNameTv.setText(followItem.getName());
            if (followItem.isFollowed()) {
                followedLayout.setVisibility(View.VISIBLE);
                followLayout.setVisibility(View.INVISIBLE);
            } else {
                followedLayout.setVisibility(View.INVISIBLE);
                followLayout.setVisibility(View.VISIBLE);
            }
        }


    }

}
